import { Injectable } from '@angular/core';
import { BaseService } from '../../../core/service/base.service';
import { _HttpClient } from '@delon/theme';
import { Observable } from "rxjs";
import { catchError, tap } from "rxjs/operators";

@Injectable({
  providedIn: 'root'
})
export class DeviceInspectionTaskService extends BaseService{

  getUrl(): string {
    return "api/device-inspection-task";
  }

  constructor(http: _HttpClient) {
    super(http);
  }

  // 获取本月的任务数量
  getMonthTask(): Observable<any> {
    const url = `${this.getUrl()}/month-task`;
    return this.http.get<any>(url).pipe(
      tap(_ => this.log(`fetched object `)),
      catchError(this.handleError<any>(`getany`)),
    );
  }

  export(taskId): Observable<any> {
    const url = `${this.getUrl()}/export-doc?taskId=${taskId}`;
    return this.http.get(url,null,{
      responseType: "blob",
    }).pipe(
      tap(_ => this.log(`fetched object `)),
      catchError(this.handleError<any>(`getany`)),
    );
  }

}
